package com.study.test.bank;

import java.util.HashMap;
import java.util.Map;

/**
 * 优惠券类型
 *
 * @author cuibaojia 2019-07-01
 */
public enum CouponTypeEnum {

    /**
     * 优惠券类型枚举
     * 1 数值/ 2 百分比 type=1 数值存分，type=2 数值存200=2%
     */
    FULL_REDUCTION(1, "满减券"),
    DISCOUNT(2, "折扣券"),
    VERTICAL_REDUCTION(3, "立减券"),
    FREE_SHIPPING(4, "包邮券");

    private Integer type;
    private String desc;
    private static Map<Integer, CouponTypeEnum> map = new HashMap(values().length);

    CouponTypeEnum(Integer type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    static {
        for (CouponTypeEnum e : values()) {
            map.put(e.getType(), e);
        }
    }

    public Integer getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public static Map<Integer, CouponTypeEnum> getMap() {
        return map;
    }

    public static CouponTypeEnum convert(Integer type) {
        return map.get(type);
    }

    public static boolean contains(Integer type) {
        return convert(type) != null;
    }
}
